<h1>Admin</h1>

<div style="border: 1px solid #999">
	<a href ="index.php?action=admin&sub_action=inserisci">inserisci nuova pagina</a>
	</div>

<?php

require_once 'funzioni.php';

connettiDb();

switch($_REQUEST['sub_action'])
{	
	case 'inserisci': visualizzaForm(); break;	
	case 'inserisciDb': inserisciPaginaDb(); break;	
	case 'modifica' : modificaPagina(); break;	
	case 'modificaDb' : modificaUtenteDB(); break;	

	
default:adminListPages();break;
}

function inserisciPaginaDb()
{
	$sql="INSERT INTO pages (title_it, title_en, content_it, content_en, section)
	VALUES ('$_POST[title_it]', 
			'$_POST[title_en]',
			'$_POST[content_it]',
			'$_POST[content_en]',
			'$_POST[section]')";
	echo $sql;
}

function visualizzaForm($dati=array(),$sub_action='inserisciDb')
{
	

include 'config.php';
?>


<form action="index.php?action=admin" method="post">
<input type="hidden" name="sub_action" value="<?php echo $sub_action;?>"/>
<input type="hidden" name="id" value="<?php echo $dati['id'];?>"/>
<label>Titolo (it)</label>
<input type="text" name="title_it" value="<?php echo $dati ['title_it'];?>"/><br />
<label>Titolo (en)</label>
<input type="text" name="title_en" value="<?php echo $dati ['title_en'];?>"/><br />

<label>Contenuto (it)</label>
<textarea rows="5" cols="50" name="content_it"><?php echo $dati['content_it'];?></textarea><br />

<label>Contenuto (en)</label>
<textarea rows="5" cols="50" name="content_en"><?php echo $dati['content_en'];?></textarea><br />

<label>sezione</label>
<select name="section">
<?php 

		foreach ($sections as $sezione=>$sottosezioni)
		{
		printf('<option value="%s">%s</option>',$sezione, $sezione);
		}
		?>

</select>

<input type="submit" value="invia" />




</form>
<?php 


}

function adminListPages(){
	
	$sql= "SELECT * FROM pages ORDER BY title_it ASC";
	$result = mysql_query($sql);
	if (mysql_num_rows($result))
	{
		echo '<table>
						<tr>
						<th>Id</th>
						<th>titolo</th>
						<th>Contenuto</th>
						</tr>';
						
						
						
		while ($row=mysql_fetch_assoc($result))
		{
			printf('<tr>
						<th>%s</th>
						<th>%s</th>
						<th>%s</th>
						</tr>',
						$row['id'], $row['title_it'],substr($row['content_it'],0,50));
		}
		echo '</table>';
	}
}

?>



